import { getRequest, postRequest } from "../baseRequest";
import { ResultData } from "@/api/types";
import { requestHttp } from "@/utils/request";

/**
 * 发布流程
 * @param data
 * @returns {AxiosPromise}
 */
export const convertBpmnRequest = (data: any) => postRequest(`/workflow/convertBpmn`, data);

/**
 * 流程设计
 * @returns {AxiosPromise}
 * @param formKey
 */
export const getBusinessDesignListRequest = (formKey: string) => getRequest(`/workflow/business/design/list/${formKey}`);
/**
 * 保存流程设计
 * @param data
 * @returns {AxiosPromise}
 */
export const saveBusinessDesignRequest = (data: any) => postRequest(`/workflow/business/design/save`, data);

/**
 * 发布流程设计
 * @param data
 * @returns {AxiosPromise}
 */
export const publishBusinessDesignRequest = (data: any) => postRequest(`/workflow/business/design/publish`, data);

/**
 * 获取流程设计
 * @returns {AxiosPromise}
 * @param formKey
 */
export const getBusinessFormRequest = (formKey: string) => getRequest(`/workflow/business/design/deployment/${formKey}`);
/**
 * 获取表单流程实例
 * 包含数据 表单项
 * @returns {AxiosPromise}
 * @param taskId
 * @param instanceId
 */
export const getBusinessProcessFormRequest = (taskId: string, instanceId: string) =>
  getRequest(`/workflow/business/process/form/`, {
    taskId: taskId,
    instanceId: instanceId
  });

/**
 * 获取流程任务携带表单属性
 * @returns {number}
 * @param taskId
 */
export const getTaskPropertyRequest = (taskId: string) => getRequest(`/workflow/business/process/property/${taskId}`);

/**
 * 获取流程表单数据
 * @param instanceId 流程实例Id
 */
export const getProcessInstanceFormData = (instanceId: string): Promise<ResultData> =>
  requestHttp.get("/workflow/business/process/form/data", { instanceId });

/**
 * 获取流程表单数据
 * @param data 流程实例Id
 */
export const notifyConfigBusinessDesign = (data: { id: number; notifyConfig: Record<string, any> }): Promise<ResultData> =>
  requestHttp.post("/business/design/notify-config", { data });

export interface BusinessDesignEntity {
  /**
   * 表单key
   */
  formKey?: string;

  /**
   * 名称
   */
  name?: string;

  /**
   * 描述
   */
  description?: string;

  /**
   * 部署Id
   */
  deploymentId?: string;

  /**
   * 版本
   */
  version?: number;

  /**
   * 流程设计内容
   */
  scheme?: { [key: string]: any };

  /**
   * 状态
   */
  status?: number;

  /**
   * 发起人配置
   */
  startUserConfig?: { [key: string]: any };

  /**
   * 通知配置
   */
  notifyConfig?: { [key: string]: any };
}
